Mask R |
您所在的位置:网站首页 › maskrcnn demo › Mask R |
https://github.com/facebookresearch/detectron2 (PyTorch implementation)
https://github.com/matterport/Mask_RCNN (Tensorflow implementation). Much of this repository was built using this repository as a reference
相关安装
建议按照教程新建anaconda环境以免冲突。 环境和库文件安装安装要求和步骤,直接执行: https://github.com/facebookresearch/maskrcnn-benchmark/blob/master/INSTALL.md conda create --name maskrcnn_benchmark conda activate maskrcnn_benchmark conda install ipython pip install ninja yacs cython matplotlib tqdm #此步骤不建议,最好离线直接安装 conda install -c pytorch pytorch-nightly torchvision cudatoolkit=9.0 export INSTALL_DIR=$PWD cd $INSTALL_DIR git clone https://github.com/cocodataset/cocoapi.git cd cocoapi/PythonAPI python setup.py build_ext install cd $INSTALL_DIR git clone https://github.com/facebookresearch/maskrcnn-benchmark.git cd maskrcnn-benchmark python setup.py build develop unset INSTALL_DIR (其中pytorch 1.0 装得很慢,而且经过测试没必要使用作者的nightly版本,直接用离线包安装1.0就行) 注意:这个build编译和安装后会把maskrcn装作一个pip库从中引用,如果编译失败会在from maskrcnn_benchmark.config import cfg报错,因为找不到该库文件。安装后conda list会有显示. 权重文件下载 权值文件作者在代码中集成了,自动下载,速度比较快,直接用他的就行。在运行demo的时候会自动检测对应位置是否有权值文件,没有的话会进行下载,下载路径很奇怪,嵌入到torch的隐藏文件夹了: cd进入文件夹可以查看下载的ResNet-50和ResNet-101模型以及网络的权重: 运行demo 两种方式利用现成参数inference webcam摄像头检测分割进入demo文件夹下,直接运行即可: python webcam.py 图片检测分割原文档没写清楚,稍微改改自己加一个文件就行,新建一个demo.py,其中写入如下: from maskrcnn_benchmark.config import cfg from predictor import COCODemo import torch import cv2 import ipdb ipdb.set_trace(context=35) config_file = "../configs/caffe2/e2e_mask_rcnn_R_101_FPN_1x_caffe2.yaml" cfg.merge_from_file(config_file) cfg.merge_from_list(["MODEL.DEVICE", "cpu"]) coco_demo = COCODemo( cfg, min_image_size=800, confidence_threshold=0.7, ) image = cv2.imread('/py/pic/2.jpg') predictions = coco_demo.run_on_opencv_image(image) cv2.imshow("COCO detections", predictions) cv2.waitKey(0) 其中更换图片路径即可,config这里用的resnet-101,如果显存不够改成50即可(700M很小了)。注意:config建议用caffe路径下的,外面的会下载预训练权重,不能检测,是留作训练用的。 运行即可: python demo.py
pytroch官网提供的预训练模型:resnet18:resnet18-5c106cde.pth和resnet50:resnet50-19c8e357.pth(两个文件打包在一起) 相关下载链接://download.csdn.net/download/qq_34374211/10618967?utm_source=bbsseo
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |